package com.young.springdemo.controller;

import com.young.springdemo.config.annotation.LogInfo;
import com.young.springdemo.config.annotation.LogOperateType;
import com.young.springdemo.jpa.entity.LogInfoEntity;
import com.young.springdemo.jpa.entity.UserEntity;
import com.young.springdemo.jpa.repository.LogInfoRepository;
import com.young.springdemo.jpa.repository.UserEntityRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: springdemo
 * @description
 * @author: Young
 * @create: 2020-05-28 14:44
 **/
@RestController
@RequestMapping(value = "jpa/controller")
@Slf4j
public class JpaController {

    @Autowired
    private UserEntityRepository userRepository;

    @GetMapping("getAllUser")
    @LogInfo(operateType = LogOperateType.QUERY)
    public List<LogInfoEntity> getAllUser(String userName) {
      log.info("获取到的用户名是[{}]",userName);
        return logInfoRepository.findAll();
    }

    @GetMapping("getUsers")
    @LogInfo(operateType = LogOperateType.QUERY)
    public List<UserEntity> getAllUser(String password,String userName) {
        log.info("获取到的用户名是[{}]",userName);
        return userRepository.findAll();
    }

    @Autowired
    private LogInfoRepository logInfoRepository;

    @GetMapping("addLog")
    public String addLog(){
        LogInfoEntity logInfoEntity = new LogInfoEntity();
        logInfoEntity.setDescription("hahah");
        logInfoEntity.setOperateType("新增");
        logInfoEntity.setUserName("张三");
        logInfoRepository.save(logInfoEntity);
        return null;
    }


}
